package com.graduate.cec.controller;


import com.graduate.cec.common.JsonPage;
import com.graduate.cec.common.JsonResult;
import com.graduate.cec.pojo.dto.RoleSimplePageDTO;
import com.graduate.cec.pojo.dto.LoginDTO;
import com.graduate.cec.pojo.entity.Permission;
import com.graduate.cec.pojo.entity.Role;
import com.graduate.cec.service.RoleService;
import com.graduate.cec.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/role",produces = "application/json;charset=utf-8")
@Api(tags = "角色")
public class RoleController {
    @Resource
    private RoleService roleService;

    /****************        增       ******************************************************************/


    @PostMapping("/insert-role")
    public JsonResult<Void> insertRole(@RequestBody Role role) {
        roleService.insertRole(role);

        return JsonResult.ok("插入成功");
    }



    /****************        删       ******************************************************************/
    //删除上传的图片
    @GetMapping("/delete-id")
    @ApiOperation("删除图片")
    public JsonResult<Void> deleteRole(Long id) {
        roleService.deleteRole(id);
        return JsonResult.ok("删除成功");
    }



    /****************        改       ******************************************************************/



    /****************        查        ******************************************************************/



    @PostMapping("/role-list")
    @ApiOperation("查询所有")
    public JsonResult<JsonPage<Role>> selectAllRole(@RequestBody RoleSimplePageDTO roleSimplePageDTO) {
        JsonPage<Role> roleJsonPage = roleService.selectAllRole(roleSimplePageDTO);
        return JsonResult.ok("查询成功",roleJsonPage);
    }

    @GetMapping("/permission-list")
    @ApiOperation("查询所有")
    public JsonResult<List<Permission>> selectAllPermission() {
        List<Permission> permissions = roleService.selectAllPermission();
        return JsonResult.ok("查询成功",permissions);
    }

    @GetMapping("/permission-list-by-id")
    @ApiOperation("查询所有")
    public JsonResult<List<Permission>> selectAllPermissionByRole(Long id) {
        List<Permission> permissions = roleService.selectAllPermissionByRole(id);
        return JsonResult.ok("查询成功",permissions);
    }

    @GetMapping("/change-permission")
    @ApiOperation("更改")
    public JsonResult<Void> changePermission(Long[] value,Long roleId) {
        roleService.changePermission(value,roleId);
        return JsonResult.ok("修改成功");
    }



}
